package myweb.myTcp;

import java.io.*;
import java.net.Socket;

public class Worker implements Runnable {
    Socket s;

    public Worker(Socket s) {
        this.s=s;
    }

    @Override
    public void run(){
        try {
            System.out.println("serve begin starting");
            InputStream inputStream = s.getInputStream();
            OutputStream outputStream = s.getOutputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            DataOutputStream dos = new DataOutputStream(outputStream);
            while (true){
                String strWord = bufferedReader.readLine();
                System.out.println("client said:"+strWord+":"+strWord.length());
                if (strWord.equalsIgnoreCase("quit")){
                    break;
                }
             String strEcho = strWord + "666";
              //dos.writeBytes(strWord + "---->"+strEcho+"/r/n")
                System.out.println("server said :"+strWord+"---->"+strEcho);
                dos.writeBytes(strWord+"--->"+strEcho+System.getProperty("line.separator"));
            }
            bufferedReader.close();
            dos.close();
            inputStream.close();
            s.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
